// app.js
import api from './api/api'
App({
  onLaunch: function () {
    // 登录
    this.getToken();
  },
  getToken() {
    // 获取OPENID及用户是否已注册
    var that = this;
    let token = wx.getStorageSync('token')
    let userInfo = wx.getStorageSync('userInfo')
    if(userInfo && !userInfo.mobile){
      wx.showModal({
        content: '您的账号信息还没完善，请先完善人个信息',
        success:function(res){
            if(res.confirm){
              wx.navigateTo({
                url: '/pages/login/login',
              })
            }
        }
      })
      return false;
    }
    if(token) return true;
    return new Promise(function (resolve, reject) {
        wx.login({
          success: res => {
            api.post('/oauth/wechatLogin' ,{
              code:res.code
            }).then(res => {
              wx.setStorageSync('token', res.token);
              wx.setStorageSync('userInfo', res.userInfo);
              // if(!res.userInfo.mobile){
              //   wx.showModal({
              //     content: '您的账号信息还没完善，请选完善人个信息',
              //     success:function(res){
              //         if(res.confirm){
              //           wx.reLaunch({
              //             url: '/pages/login/login',
              //           })
              //         }
              //     }
              //   })
              // }
              resolve(res);
            })
          }
        })
    })
  },
  ul:{
    host:'http://www.erp.com/api/v1',
    main:"",
    login:"",
    address_list:"/api/v1/user/address/lists",//地址列表
    add_address:"/api/v1/user/add/address",//添加地址
    edit_address:"/api/v1/user/address/default",//编辑地址
  }
})
